<?php
namespace app\admin\model;

use think\Model;
                    

class SaasBOrder extends Model
                    
{
                    
    public function getAll($where){
                    
        $rs = SaasBOrder::where($where)
                    
        ->select();
                    
        return $rs;
                    
    }

    public function getAllJoinGoods($where){

        $rs = SaasBOrder::alias('sbo')

            ->where('sbo.order_code','=',$where['order_code'])

            ->join('saas_goods sg','sg.id = sbo.goods_id','LEFT')

            ->join('saas_business sb','sg.b_id = sb.id','LEFT')

            ->field('sbo.*,sg.goods_name as sg_goods_name,sg.img as sg_img,sb.name as sb_name')

            ->select();

        return $rs;

    }
                    
    public function getOne($where){
                    
        $rs = SaasBOrder::where($where)
                    
        ->find();
                    
        return $rs;
                    
    }

    public function getOneJoinGoods($where){

        $rs = SaasBOrder::alias('sbo')

            ->where('sbo.order_code','=',$where['order_code'])

            ->join('saas_goods sg','sg.id = sbo.goods_id','LEFT')

            ->field('sbo.*,sg.goods_name as sg_goods_name,sg.img as sg_img')

            ->find();

        return $rs;

    }
                    
    public function add($data){
                    
        $rs = SaasBOrder::data($data)
                    
        ->save();
                    
        return $rs;
                    
    }
                    
    public function edit($where,$data){
                    
        $rs = SaasBOrder::where($where)
                    
        ->update($data);
                    
        return $rs;
                    
    }
                    
    public function del($where){
                    
        $rs = SaasBOrder::where($where)
                    
        ->delete();
                    
        return $rs;
                    
    }
                    
}
                    
